package com.huawei.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**

 * 删除文件或目录
 */
public class DeleteFile {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        //conf.set("fs.defaultFS", "hdfs://master:9000");
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path(args[0]);
        //exists判断的不仅仅是目录也是文件，使用delete可以将文件或者目录删除
        if (fs.exists(path)) {
            fs.delete(path,true);
            System.out.println("删除成功");
        }else{
            System.out.println("文件不存在");
        }
        fs.close();
    }
}